package com.mhkj.base.rbac.user.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mhkj.base.rbac.user.entity.SystemUser;
import com.mics.core.system.base.repository.BaseRepository;

/**
 * 系统用户
 * @author mics
 * @date 2018年9月1日
 * @version 1.0
 */
public interface SystemUserRepository extends BaseRepository<SystemUser>{

	@Query("select t from SystemUser t where t.oaId=:oaId")
	SystemUser findByOaId(@Param("oaId")String uid);

	@Query(value="SELECT r.* FROM t_system_user u left join t_sys_role_user ru on u.id = ru.sys_user_id LEFT JOIN t_sys_role r ON r.id = ru.sys_role_id where u.login_name = :loginName",nativeQuery=true)
	List<Object[]> getUserRole(@Param("loginName")String loginName);

	@Query("select t from SystemUser t where t.name=:name")
	SystemUser getByName(@Param("name")String name);
	
	@Query("select t from SystemUser t where t.loginName=:loginName")
	SystemUser getByLoginName(@Param("loginName")String loginName);

}
